package com.huawei.appgallery.assistantdock.subaccount;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewStub;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.gamebox.plugin.gameservice.bean.GameInfo;
import com.huawei.gamebox.plugin.gameservice.bean.GameSubAcct;
import com.huawei.hwid.core.constants.HwAccountConstants;
import java.util.ArrayList;
import java.util.List;
import o.beo$d;
import o.beo$e;
import o.beo$i;
import o.beo$j;
import o.beo.f;
import o.bjc;
import o.BaseAlertDialog;
import o.Logger;
import o.dof;
import o.ezq;
import o.ezv;

public class SwitchGameSubAccDialog extends BaseAlertDialog {
    private static CharSequence ʻ = "";
    private GameSubAcct ʼ = null;
    private int ʽ = 0;
    private ListView ˋ = null;
    private RelativeLayout ˎ;
    protected Activity ॱ;
    private MyAdapter ॱˊ = null;
    private List<GameSubAcct> ॱॱ = null;
    private int ᐝ = 0;

    class MyAdapter extends BaseAdapter {
        private ImageView imageView = null;
        private LayoutInflater layoutInflater;
        private List<GameSubAcct> mList;
        private TextView nameTextView = null;
        private TextView timeView = null;

        public MyAdapter(List<GameSubAcct> list) {
            this.mList = list;
            this.layoutInflater = LayoutInflater.from(SwitchGameSubAccDialog.this.ॱ);
        }

        public int getCount() {
            return this.mList.size();
        }

        public Object getItem(int i) {
            return this.mList.get(i);
        }

        public long getItemId(int i) {
            return (long) i;
        }

        public View getView(int i, View view, ViewGroup viewGroup) {
            if (view == null) {
                view = this.layoutInflater.inflate(beo$j.ʼॱ, null);
            }
            this.nameTextView = (TextView) view.findViewById(beo$e.ˌॱ);
            CharSequence charSequence = "";
            if (!(this.mList == null || this.mList.get(i) == null)) {
                charSequence = ((GameSubAcct) this.mList.get(i)).ˎ();
            }
            if (i == 0) {
                charSequence = SwitchGameSubAccDialog.this.ॱ.getResources().getString(f.ʼˊ);
            }
            this.nameTextView.setText(charSequence);
            this.timeView = (TextView) view.findViewById(beo$e.ˋʻ);
            String str = "";
            if (!(this.mList == null || this.mList.get(i) == null)) {
                str = ((GameSubAcct) this.mList.get(i)).ˋ();
            }
            this.timeView.setText(SwitchGameSubAccDialog.this.ॱ(str));
            this.imageView = (ImageView) view.findViewById(beo$e.ॱʼ);
            this.imageView.setBackgroundResource(SwitchGameSubAccDialog.this.ʽ == i ? beo$d.ॱ : beo$d.ˊ);
            return view;
        }
    }

    class a implements OnItemClickListener {
        final /* synthetic */ SwitchGameSubAccDialog ॱ;

        private a(SwitchGameSubAccDialog switchGameSubAccDialog) {
            this.ॱ = switchGameSubAccDialog;
        }

        public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
            if (Logger.ˎ()) {
                Logger.ˏ("SwitchGameSubAccDialog", "onItemClick:" + i);
            }
            GameSubAcct gameSubAcct = (GameSubAcct) ((ListView) adapterView).getItemAtPosition(i);
            if (gameSubAcct != null) {
                this.ॱ.ॱ(gameSubAcct, i == this.ॱ.ʽ);
            }
        }
    }

    public SwitchGameSubAccDialog(Activity activity) {
        super(activity, activity.getResources().getString(f.ʼᐝ), ʻ);
        this.ॱ = activity;
    }

    public static SwitchGameSubAccDialog ˊ(Activity activity) {
        if (activity.isFinishing()) {
            return new bjc(activity);
        }
        SwitchGameSubAccDialog switchGameSubAccDialog = new SwitchGameSubAccDialog(activity);
        switchGameSubAccDialog.ˏ(activity);
        return switchGameSubAccDialog;
    }

    protected void ˏ(Activity activity) {
        this.ˎ = (RelativeLayout) LayoutInflater.from(this.ॱ).inflate(beo$j.ˊᐝ, null);
        ˏ(BaseAlertDialog.a.ˋ, 8);
        ˏ(BaseAlertDialog.a.ॱ, 8);
        ˊ(this.ˎ);
        ʽ();
        this.ॱॱ = ezv.ॱ().ˊ();
    }

    private void ˊ() {
        try {
            Logger.ˏ("SwitchGameSubAccDialog", "start to show the sub-account");
            ᐝ();
            List arrayList = new ArrayList();
            if (this.ॱॱ != null) {
                arrayList.addAll(this.ॱॱ);
            }
            this.ᐝ = arrayList.size();
            if (Logger.ˎ()) {
                Logger.ˏ("SwitchGameSubAccDialog", "the game sub-account number is " + this.ᐝ);
            }
            GameInfo ˎ = ezv.ॱ().ˎ();
            String ˎ2 = ezq.ˏ().ˎ(ˎ != null ? ˎ.getPackageName() : "");
            for (int i = 0; i < arrayList.size(); i++) {
                GameSubAcct gameSubAcct = (GameSubAcct) arrayList.get(i);
                if (!(gameSubAcct == null || gameSubAcct.ˏ() == null || !gameSubAcct.ˏ().equals(ˎ2))) {
                    this.ʽ = i;
                }
            }
            this.ॱˊ = new MyAdapter(arrayList);
            this.ˋ.setAdapter(this.ॱˊ);
        } catch (Throwable e) {
            Logger.ˋ("SwitchGameSubAccDialog", e.getMessage(), e);
        }
    }

    private void ʽ() {
        this.ʼ = new GameSubAcct();
        this.ʼ.ˋ(UserSession.getInstance().getAuthAccount());
        this.ʼ.ॱ(UserSession.getInstance().getUserId());
        this.ʼ.ˊ(UserSession.getInstance().getUserId());
    }

    private void ᐝ() {
        if (this.ˎ != null) {
            this.ˋ = (ListView) this.ˎ.findViewById(beo$e.ʾॱ);
            this.ˋ.setOnItemClickListener(new a());
        }
    }

    private void ॱ(GameSubAcct gameSubAcct, boolean z) {
        if (Logger.ˎ()) {
            Logger.ˏ("SwitchGameSubAccDialog", "come into goIntoThisAccount");
        }
        if (!z) {
            ezv.ॱ().ˋ(gameSubAcct);
        }
        this.ॱ.finish();
    }

    public void ॱ() {
        ˊ();
        this.ˋ.addFooterView(new ViewStub(this.ॱ));
        try {
            super.ॱ();
            ˎ(true);
            ॱ(false);
            if (ˋ() != null) {
                ˋ().setOnDismissListener(new OnDismissListener(this) {
                    final /* synthetic */ SwitchGameSubAccDialog ˎ;

                    {
                        this.ˎ = r1;
                    }

                    public void onDismiss(DialogInterface dialogInterface) {
                        dialogInterface.dismiss();
                        this.ˎ.ॱ.finish();
                    }
                });
            }
        } catch (Throwable e) {
            Logger.ˋ("SwitchGameSubAccDialog", e.getMessage(), e);
        }
    }

    protected String ॱ(String str) {
        if (dof.ॱ(str)) {
            return this.ॱ.getResources().getString(f.ʻˋ);
        }
        long currentTimeMillis = System.currentTimeMillis() - Long.parseLong(str);
        if (currentTimeMillis < 60000) {
            return ʻ();
        }
        if (currentTimeMillis < 3600000) {
            return ˋ(currentTimeMillis);
        }
        if (currentTimeMillis < HwAccountConstants.CHECK_SITE_COUNTRY_DURATION) {
            return ॱ(currentTimeMillis);
        }
        if (currentTimeMillis < 2592000000L) {
            return ˊ(currentTimeMillis);
        }
        if (currentTimeMillis < 31104000000L) {
            return ˏ(currentTimeMillis);
        }
        return ˎ(currentTimeMillis);
    }

    private String ʻ() {
        return this.ॱ.getResources().getString(f.ʻᐝ);
    }

    private String ˋ(long j) {
        int i = (int) (j / 60000);
        return this.ॱ.getResources().getQuantityString(beo$i.ˏ, i, new Object[]{Integer.valueOf(i)});
    }

    private String ॱ(long j) {
        int i = (int) (j / 3600000);
        return this.ॱ.getResources().getQuantityString(beo$i.ˎ, i, new Object[]{Integer.valueOf(i)});
    }

    private String ˊ(long j) {
        int i = (int) (j / HwAccountConstants.CHECK_SITE_COUNTRY_DURATION);
        return this.ॱ.getResources().getQuantityString(beo$i.ˊ, i, new Object[]{Integer.valueOf(i)});
    }

    private String ˏ(long j) {
        int i = (int) (j / 2592000000L);
        return this.ॱ.getResources().getQuantityString(beo$i.ॱ, i, new Object[]{Integer.valueOf(i)});
    }

    private String ˎ(long j) {
        int i = (int) (j / 31104000000L);
        return this.ॱ.getResources().getQuantityString(beo$i.ˋ, i, new Object[]{Integer.valueOf(i)});
    }
}
